<template>
  <van-checkbox-group v-model="data.values" @change="change">
    <van-cell-group>
      <template #title>
        <span style="color: red" v-if="required">*</span>
        {{ name }}
      </template>
      <van-cell v-for="(opt, index) in options" clickable :key="index" :title="opt.Text">
        <template #right-icon>
          <van-checkbox :name="opt.Text" ref="checkboxes" />
        </template>
      </van-cell>
    </van-cell-group>
  </van-checkbox-group>
</template>
<script>
export default {
  props: ['value', 'disabled', 'props', 'required', 'isBusiness'],
  data: function () {
    return {
      data: {
        values: [],
        displayName: '',
      },
    }
  },
  computed: {
    myprops() {
      return this.props ? this.props : []
    },
    name() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'name')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? val.BFFP_Value : '多选'
        } else {
          return val.FFLP_Value ? val.FFLP_Value : '多选'
        }
      }
      return '多选'
    },
    options() {
      let val = this.myprops.find((x) => x.FLPR_Code == 'options')
      if (val) {
        if (this.isBusiness) {
          return val.BFFP_Value ? JSON.parse(val.BFFP_Value) : []
        } else {
          return val.FFLP_Value ? JSON.parse(val.FFLP_Value) : []
        }
      }
      return []
    },
  },
  methods: {
    change() {
      this.data.displayName = JSON.stringify(this.data.values)
      this.$emit('input', JSON.stringify(this.data))
      this.$emit('display', this.data.displayName)
    },
  },
  mounted: function () {
    if (this.value && Object.keys(this.value).length) {
      this.data = JSON.parse(this.value)
    }
  },
}
</script>
<style scoped>
.el-form-item {
  margin: 10px !important;
}
</style>